package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.Callable;

public class GenericDemo{
    public static void main(String[] args) {
        /*
        Collection<String> c=new ArrayList<>();
        c.add("one");
        c.add("two");
        //c.add(123);编译错误,123不是c集合所指泛型的实际类型String;

        //迭代器的泛型类型要与集合数组的泛型类型一致
        Iterator<String> it=c.iterator();
        while(it.hasNext()){
            String str=it.next();
            System.out.println(str);
        }

        for(String s:c){
            System.out.println(s);
        }
        */
        Collection<Point> c=new ArrayList<>();
        c.add(new Point(1,2));
        c.add(new Point(3,4));
        c.add(new Point(5,5));
        c.add(new Point(6,6));

        Iterator<Point> it=c.iterator();
        while(it.hasNext()){
            Point p=it.next();
            System.out.println(p);
        }














    }
}
